void load_config() {

  char k[40];
  char *pk;
  char v[80];
  char *pv;
  char c;
  
  Serial.println(F("Loading config..."));
  pinMode(10, OUTPUT);  // required for SD operation
 
  if (!SD.begin(PIN_SPI_CS_SD)) {
    Serial.println(F("Card failed or not present -- using defaults"));
    return;
  }
 
  File dataFile = SD.open("config.txt");
  if (!dataFile) {
    Serial.println(F("Error opening config.txt -- using defaults"));
    return;
  }
  
  c = dataFile.read();
  while (c != -1) {
    pk = k;
    pv = v;
    while ((c != -1) && (c != '=')) {
      *pk++ = c;
      c = dataFile.read();
    }
    c = dataFile.read();  // eat equal sign
    while ((c != -1) && (c != '\n')) {
      *pv++ = c;
      c = dataFile.read();
    }
    c = dataFile.read();  // eat newline
    *pk = '\0';
    *pv = '\0';
    if (strcmp(k, "ip") == 0) {
      Serial.print(F("IP:"));
      Serial.println(v);
      ipaddr = get_ip(v);
    }
    if (strcmp(k, "gateway") == 0) {
      Serial.print(F("gateway:"));
      Serial.println(v);
      gateway = get_ip(v);
    }
    if (strcmp(k, "dns") == 0) {
      Serial.print(F("dns:"));
      Serial.println(v);
      dnsaddr = get_ip(v);
    }
    if (strcmp(k, "netmask") == 0) {
      Serial.print(F("netmask:"));
      Serial.println(v);
      netmask = get_ip(v);
    }
    if (strcmp(k, "mac") == 0) {
      Serial.print(F("MAC:"));
      Serial.println(v);
      get_mac(v, mac);
    }
  }
     
  dataFile.close();
  
}

IPAddress get_ip(char *s) {
  uint8_t a[4];
  a[0] = get_int(s);
  a[1] = get_int();
  a[2] = get_int();
  a[3] = get_int();
  return IPAddress(a);
}

void get_mac(char *s, byte mac[]) {
  mac[0] = get_int_hex(s);
  mac[1] = get_int_hex();
  mac[2] = get_int_hex();
  mac[3] = get_int_hex();
  mac[4] = get_int_hex();
  mac[5] = get_int_hex();
}

